package com.ipc.app.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ipc.app.biz.OrderBiz;
import com.ipc.app.constants.OrderStatusConstants;
import com.ipc.app.constants.SessionConstants;
import com.ipc.app.model.Order;

@Controller
@RequestMapping(value = "/jsp/bookSeat.do")
public class BookSeatAction {

	@Autowired
	private OrderBiz orderBiz;

	@RequestMapping(method = RequestMethod.POST)
	public String bookSeat(ModelMap model, HttpServletRequest request,
			String informationId) {
		String userID = (String) request.getSession().getAttribute(
				SessionConstants.LOGIN_USER_ID);
		Order order = orderBiz.bookSeat(informationId, userID);
		if (null == order) {
			return "orderFailed";
		}
		model.addAttribute("order", order);
		if (OrderStatusConstants.BOOKED_NOT_PAY.equals(order.getStatus())) {
			return "payment";
		}
		return "orderSuccess";

	}
}
